pp108 : Constraint Logic on Objects and Attributes

Constraint Logic on Objects and Attributes

This topic describes the constraint logic on objects and attributes.


Constraint logic is useful when you want to check the validity of objects and attributes before they are persisted into the database. In a transaction flow, it is necessary to check if the participating objects and attributes are appropriate to the context. Constraint logic on objects checks the validity of multiple attributes in the context of the object, whereas constraint logic on attributes checks if correct values are defined.

To apply constraint logic to the objects and attributes, you can use the constraint listeners. These constraint listeners can either be used implicitly or explicitly.

Tip: Constraints on attributes can also be set in the BTX file.

Applying Constraint Logic on an Object


USING IMPLICIT LISTENER

Use the onConstraint listener to write application logic to check for constraints.

USING EXPLICIT LISTENER

Register a class that implements the IObjectConstraintListener interface, and use the onObjectConstraint method to write the application logic.

Applying Constraint Logic on an Attribute


USING IMPLICIT LISTENER

Implement the onConstraint_<Attribute Name> method in the extension class.

USING IMPLICIT LISTENER

Register a class that implements the IAttributeConstraintListener , and use the onAttributeConstraint method to write the application logic.

For further information on using these methods, see the WS-AppServer SDK.

Note: Even if the constraint logic is set on an object, the constraint check will be performed only if the qConstraint attribute for that object is set to

1.

Constraint Violations and Exceptions


When you validate an object using the Validate request, if a constraint is violated, an error message is reported to the method that is called. You can use the adderror method in the AttributeConstraintEvent object to report constraint violations. The error message is included in the XML response as an attribute calledmsg-error. WS-AppServer checks for constraint violations in the entire object and reports the errors collectively.

Alternatively, WS-AppServer reports constraint violations through exceptions. When you use an insert or an update request, WS-AppServer throws an exception (BsfConstraintViolationException) as soon as an error is reported.

Related reference

ValidateObject
Validate BusObject SOAP Request
Initialization of Objects and Attributes
Repetitive Validation